package recycle.controller;

import recycle.pojo.Productinfo;
import recycle.service.ProductinfoService;
import recycle.utils.Page;
import recycle.vo.ProductinfoParam;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.alibaba.dubbo.config.annotation.Reference;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 描述：商品信息表 控制器
* @author 孙冉
* @date 2019/07/22
*/
@RestController
@RequestMapping("/productinfo")
public class ProductinfoController{
	@Resource
	private ProductinfoService productinfoService;
 	
 	@RequestMapping("/findById.json")
    public Productinfo findById(Integer productId){
        Productinfo result = null;
        try {
            result = productinfoService.findById(productId);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：获取所有的Productinfo对象
     */
    @RequestMapping("/findAll.json")
    public List<Productinfo> findAll(){
        List<Productinfo> result = null;
        try {
            result = productinfoService.findAll();
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：新增保存Productinfo对象
     */
    @RequestMapping("/save.json")
    public Map save(Productinfo productinfo){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存商品信息表失败");
        try {
            if(productinfoService.save(productinfo)>0){
                result.put("flag",true);
                result.put("msg","保存商品信息表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：根据主键删除商品信息表对象
     * @param productId
     */
    @RequestMapping("/delete.json")
    public Map delete(Integer productId){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","保存商品信息表失败");
        try {
            if(productinfoService.delete(productId)>0){
                result.put("flag",true);
                result.put("msg","保存商品信息表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 描述：更新商品信息表对象
     */
    @RequestMapping("/update.json")
    public Map update(Productinfo productinfo){
        Map result = new HashMap();
        result.put("flag",false);
        result.put("msg","更新商品信息表失败");
        try {
            if( productinfoService.update(productinfo)>0){
                result.put("flag",true);
                result.put("msg","更新商品信息表成功");
            }
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;

    }

    /**
     * 根据不确定的条件，动态查询
     */
    @RequestMapping("/query.json")
    public List<Productinfo> query(ProductinfoParam param){
        List<Productinfo> result = null;
        try {
            result = productinfoService.query(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    /**
     * 根据不确定的条件，动态分页查询
     */
    @RequestMapping("/queryByPage.json")
    public Page queryByPage(ProductinfoParam param){
        Page result = null;
        try {
            result = productinfoService.queryByPage(param);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping("/queryProductInProductList.json")
    public List<Productinfo> queryProductInProductList(Integer oneCategory,Integer twoCategory){
        List<Productinfo> pifList = productinfoService.selectProductInProductList(oneCategory,twoCategory);
        return pifList;
    }






    @RequestMapping("/findByByproductName.json")
    public  Productinfo findByproductName(String productName){
        Productinfo result = null;
        try {
            result = productinfoService.findByproductName(productName);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }


    @RequestMapping("/findByproductcategory.json")
    public Productinfo findByproductcategory(String productcategory){
        Productinfo result = null;
        try {
            result = productinfoService.findByproductcategory(productcategory);
        }catch (Exception e){
            e.printStackTrace();
        }
        return result;
    }

    @RequestMapping("/selectAllAppleProduct.json")
    public List<Productinfo> selectAllAppleProduct(){
        return productinfoService.selectProductInProductList(1,1);
    }

    @RequestMapping("/selectAllHuaWeiProduct.json")
    public List<Productinfo> selectAllHuaWeiProduct(){
        return productinfoService.selectProductInProductList(1,2);
    }

    @RequestMapping("/selectAllXiaoMiProduct.json")
    public List<Productinfo> selectAllXiaoMiProduct(){
        return productinfoService.selectProductInProductList(1,3);
    }
 }
